package com.hunau.novel_reading.service.impl;

import com.hunau.novel_reading.common.ResultCodeEnum;
import com.hunau.novel_reading.entity.Books;
import com.hunau.novel_reading.exception.BusinessException;
import com.hunau.novel_reading.mapper.BooksMapper;
import com.hunau.novel_reading.request.BooksSeekByBookId;
import com.hunau.novel_reading.request.BooksSeekReq;
import com.hunau.novel_reading.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BooksServiceImpl implements BooksService {
    @Autowired
    private BooksMapper booksMapper;
    @Override
    public List<Books> getBooks() {
        return booksMapper.selectAll();
    }
    @Override
    public List<Books> getBooksByBookNameOrType(BooksSeekReq booksSeekReq) {
        List<Books> result = booksMapper.selectNovelsByBookNameOrType(booksSeekReq.getKeyword());
        if (result == null){
            throw new BusinessException(ResultCodeEnum.Key_NOT_EXISTS);
        }
        return result;
    }
    @Override
    public List<Books> selectBookByBookId(BooksSeekByBookId booksSeekByBookId) {
        return booksMapper.selectBookByBookId(booksSeekByBookId.getBookId());
    }
}
